require('../../assets/css/index.less');
require('./mine.less')
require('./iconfont/iconfont.css');
// 引入tabe渲染样式
let renderTabbar= require('../../xios/tabe')
// 引用swiper的css
require('swiper')
//引入axios
const request= require('../../xios/axios')
// 引入swiper
const mySwiper = require('swiper/dist/css/swiper.min.css');


window.onload = () => {
  renderTabbar('mine')
  const API='http://fitness.h5.itsource.cn:3701'
    // 打卡
   let Clock_box_span= document.querySelector('.Clock_box_span');
//    今日打卡
let Clock_box_p=document.querySelector('.Clock_box_p');
// 运动分钟
let Sports_left_span=document.querySelector('.Sports_left_span');
let Sports_left_span22=document.querySelector('.Sports_left_span22');

let user_name_p=document.querySelector('.user_name_p');
// 头像
let user11=document.querySelector('#user11');
// 本周消耗

    // 使用swiper
    let mySwiper = new Swiper('.swiper-container', {
        autoplay: 1000,//可选选项，自动滑动
        initialSlide: 0,
        pagination: '.swiper-pagination',
        loop: true,
    })
    // 获取打卡
request.get('/api/user/clockInInfo').then((res=>{
         console.log(res);
         let {errno,data}=res.data
        if(errno===0){
          Clock_box_span.textContent=data.clockCount
        }
}))
    // 获取用户打卡
    request.get('/api/user/clockInInfo').then((res=>{
       let{errno,data}=res.data
       if(errno===0){
          if(data.clockCount){
            Clock_box_p.textContent=`今日已打卡`
            Clock_box_p.className='acdd'
          }else{
            Clock_box_p.className='acdd'
          }
       }
}))
// 获取用户信息
function fa(){
  return request.get('/api/user/info').then((res=>{
    let{errno,data}=res.data
    console.log(res.data);
    user_name_p.textContent=data.nickName

}))

}
console.log(fa());

// 获取运动数据
request.get('/api/exercise').then((res=>{
  let {errno,data}=res.data;
    console.log(res);
     if(errno===0){
      Sports_left_span22.textContent=data.sum7Duration
      Sports_left_span.textContent=data.sum7Calorie

     }
}))
Clock_box_p.addEventListener('click',function(){
      request.post('/api/user/clockIn').then((err=>{
             request.get('/api/user/clockInInfo').then((err=>{
                let {errno,message}=err.data
                console.log(err);
                if(errno===0){
                    Clock_box_p.textContent='今日已打卡'
                    Clock_box_p.className='acdd'
                } else{
                  Clock_box_p.textContent='今日打卡'
                  Clock_box_p.className='Clock_box_p'
                }
             }))
      }))
})
//获取运动勋章
// // 渲染
// function fa(data){
//   Clock_box_span.textContent=data.clockCount
//   // 运动总时长
//   Sports_left_span.textContent=data.sumDuration
//   // 本周消耗
//   Sports_left_span2.textContent=data.calorie
// }

//渲染头像
  request.get('/api/user/info').then((res=>{
    let{errno,data}=res.data
     if(errno===0){
       user11.src=API + data.imgUrl
     }
}))
}

